<template>
  <div id="jinshengIndex">
    <el-dialog title="人员信息详情" :visible.sync="personDetailVisible" width="80%" top="20px" append-to-body :close-on-click-modal="false" :close-on-press-escape="false">
      <personInfo :personId='personId' :hidemoredetail="true"></personInfo>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <!-- <el-breadcrumb-item>人才建设</el-breadcrumb-item> -->
      <el-breadcrumb-item>职级晋升年限提示</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <h1>职级晋升年限提示</h1>
      <div style="padding:10px">
        <el-radio-group  v-model="levelIndex">
          <template  v-for="(item,index) in list">
            <el-radio-button :key="index" :label="index" v-if="item.children&&item.children.length>0">{{item.nextLevel}}{{item.children.length}}人</el-radio-button>
          </template>
        </el-radio-group>
            <el-dropdown split-button type="primary" @click="exportAllData" style="right:15px;top:168px;position: fixed;">
              导出数据
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="exportAllPerson">导出司局全部人员</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
      </div>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <el-table :data="list[levelIndex]?list[levelIndex].children:[]" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border :row-class-name="tableRowClassName">
        <el-table-column type="index" label="序号" width="50" align="center" class-name="tableth" />
        <el-table-column prop="a0101" label="姓名" width="100" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.a0101" @click="detail(scope.row.a0184)" style="cursor:pointer;color:#0058AC;font-weight:bolder">{{scope.row.a0101}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="unitName" label="单位" width="260" show-overflow-tooltip />
        <el-table-column prop="a0221" label="现职务层次" width="100" align="center" show-overflow-tooltip />
        <el-table-column prop="a0288" label="任现职务层次时间" width="140" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ formatJobDate(scope.row.a0288) }}
          </template>
        </el-table-column>
        <el-table-column prop="a0192E" label="现职级" width="110" align="center" show-overflow-tooltip />
        <el-table-column prop="a0192C" label="任现职级时间" width="130" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ formatJobDate(scope.row.a0192C) }}
          </template>
        </el-table-column>
        <el-table-column prop="a0192X" label="任相当层次职务职级时间" width="130" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ formatJobDate(scope.row.a0192X) }}
          </template>
        </el-table-column>
        <el-table-column prop="a0107" label="出生年月" width="130" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ formatJobDate(scope.row.a0107) }}
          </template>
        </el-table-column>
        <el-table-column prop="gender" label="性别" width="80" align="center" show-overflow-tooltip />
        <el-table-column prop="age" label="年龄" width="80" align="center" show-overflow-tooltip />
        <el-table-column prop="remarks" label="备注" min-width="200">
          <template slot-scope="scope">
            <div v-html="scope.row.remarksHtml" />
          </template>
        </el-table-column>
      </el-table>
    </section>
  </div>
</template>

<script>
import personInfo from '@/person/Detail.vue'
export default {
  components: {
    personInfo
  },
  data () {
    return {
      filters: {
        includeCgs: true
      },
      listLoading: false,
      tableHeight: 100,
      list: [
      ],
      levelIndex: 0,
      personDetailVisible: false,
      personId: null
    }
  },
  methods: {
    persondetail (id) {
      this.personDetailVisible = true
      this.personId = id
    },
    detail (idcardNo) {
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/jiben/getIdByIdCardNo?idcard=` + idcardNo)
        .then(response => {
          if (response.data.success) {
            if (response.data.result) {
              this.persondetail(response.data.result)
            } else {
              this.$message({
                message: '无此人选的干部全方位情况',
                type: 'error'
              })
            }
          } else {
            this.$message({
              message: '查询失败:无此人选的干部全方位情况',
              type: 'error'
            })
          }
        })
        .catch(() => {
          this.$message({
            message: '查询失败:无此人选的干部全方位情况',
            type: 'error'
          })
        })
    },
    tableRowClassName ({row}) {
      if (row.flag) {
        return 'jinshengTableRowBolder'
      } else {
        return ''
      }
    },
    formatJobDate (str) {
      if (str) {
        if (str.length === 6 && /^[0-9]*$/.test(str)) { // yyyymm
          return str.substr(0, 4) + '.' + str.substr(4)
        }
        if (str.length === 8 && /^[0-9]*$/.test(str)) { // yyyymmdd
          return str.substr(0, 4) + '.' + str.substr(4, 2) + '.' + str.substr(6, 2)
        } else {
          return str
        }
      }
    },
    exportAllData () {
      window.open(this.$http.defaults.baseURL + this.$http.defaults.jinshengAPI + `api/promotion/getExport`)
    },
    exportAllPerson () {
      window.open(this.$http.defaults.baseURL + this.$http.defaults.jinshengAPI + `api/promotion/getExportAll`)
    },
    getList () {
      this.listLoading = true
      this.$http
        .get(this.$http.defaults.jinshengAPI + `api/promotion/queryUsers`)
        .then(response => {
          this.listLoading = false
          if (response.data.success) {
            this.list = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
            console.log(response.data.message)
          }
        })
        .catch(error => {
          this.listLoading = false
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      let myheight = 253
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - myheight
      })
    }
  },
  mounted () {
    this.getList()
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
#jinshengIndex .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #jinshengIndex .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
  #jinshengIndex .el-table--border th,#jinshengIndex .el-table--border td {
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
  #jinshengIndex .el-table .el-table__cell{
    padding: 2px 0;
  }
  #jinshengIndex .el-radio-button__inner{
    padding: 12px 5px !important;
  }
  .jinshengTableRowBolder{
    font-weight: bolder;
    background: #FFE8E8 !important;
  }
</style>
<style scoped>
  #jinshengIndex .el-button{
    color:#fff !important;
  }
  #jinshengIndex h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #jinshengIndex .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
